﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LengthAiCalculate
{
    internal class 组合
    {
        private static void 取指定长度的组合()
        {
            double[] arr = new double[] { 6, 6.5, 7, 7.5, 8 };
            int n = 3;//长度为2以内的所有组合
            List<double[]> list = new List<double[]>();
            foreach (double s in arr)
            {
                List<double[]> lst = list.Where(p => p.Length < n).ToList();
                double[] nArr = { s };
                list.Add(nArr);
                foreach (double[] ss in lst)
                {
                    list.Add(ss.Concat(nArr).ToArray());
                }
            }
            List<double[]> outList = list.OrderByDescending(p => p.Length).ToList();
            outList.ForEach(p => Console.WriteLine(string.Join(",", p)));
            System.Console.ReadLine();
        }

        private static void 全组合()
        {
            string[] arr = new string[] { "a", "b", "c", "d", "e" };
            List<string[]> list = new List<string[]>();
            foreach (string s in arr)
            {
                List<string[]> lst = list.GetRange(0, list.Count);
                string[] nArr = { s };
                list.Add(nArr);
                foreach (string[] ss in lst)
                {
                    list.Add(ss.Concat(nArr).ToArray());
                }
            }
            List<string[]> outList = list.OrderByDescending(p => p.Length).ToList();
            outList.ForEach(p => Console.WriteLine(string.Join(",", p)));
            System.Console.ReadLine();
        }
    }
}